package com.generator.controller.column;

import com.generator.entity.column.Column;
import com.generator.service.column.ColumnService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/generate")
@CrossOrigin(allowCredentials = "true")
public class ColumnController {

    @Autowired
    private ColumnService columnService;

    @GetMapping("/findAllColumns")
    public List<Column> findAllColumns(){
        return columnService.findAllColumns();
    }

    @GetMapping("/addColumn")
    public void addColumn(@Param("column")Column column){
        columnService.addColumn(column);
    }

    @GetMapping("/delColumn")
    public void delColumn(@Param("columnId")int columnId){
        columnService.delColumn(columnId);
    }

    @GetMapping("/updateColumn")
    public void updateColumn(@Param("column")Column column){
        columnService.updateColumn(column);
    }

    @GetMapping("/findColumnById")
    public Column findColumnById(@Param("columnId")int columnId){
        return columnService.findColumnById(columnId);
    }

}
